/* Ekeko - Server based resource loader
 * Copyright (C) 2013 Jorge Luis Zapata
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "ekeko_common.h"
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
/*============================================================================*
 *                                 Global                                     *
 *============================================================================*/
Eix_Message * EKEKO_MSG_CONTEXT_GET;
Eix_Message * EKEKO_MSG_CONTEXT_GET_REPLY;
Eix_Message * EKEKO_MSG_CONTEXT_FREE;
Eix_Message * EKEKO_MSG_IMAGE_LOAD;
Eix_Message * EKEKO_MSG_IMAGE_LOAD_REPLY;
Eix_Message * EKEKO_MSG_IMAGE_FREE;

/* TODO we need to create simplified functions/macros for:
 * - creating structs that are always accesible (no new, delete, etc, etc)
 * - add a function for simple properties (i.e no constraints, etc)
 * - add a macro that will generate the offsetof, etc
 */
void ekeko_common_message_init(void)
{
	Ender_Namespace *ns;
	Ender_Descriptor *d;
	Ender_Container *c;
	Ender_Property *p;

	/* register the messages */
	ns = ender_namespace_new("Ekeko", 0);
	/* the context get reply */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Context_Get_Reply",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Context_Get_Reply));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "id", c,
			offsetof(Ekeko_Msg_Context_Get_Reply, id));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "size", c,
			offsetof(Ekeko_Msg_Context_Get_Reply, size));
	c = ender_container_new(ENDER_STRING);
	p = ender_descriptor_struct_property_add(d, "name", c,
			offsetof(Ekeko_Msg_Context_Get_Reply, name));
	EKEKO_MSG_CONTEXT_GET_REPLY = eix_message_add(d, NULL, 0);

	/* the context get */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Context_Get",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Context_Get));
	c = ender_container_new(ENDER_STRING);
	p = ender_descriptor_struct_property_add(d, "name", c,
			offsetof(Ekeko_Msg_Context_Get, name));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "size", c,
			offsetof(Ekeko_Msg_Context_Get, size));
	EKEKO_MSG_CONTEXT_GET = eix_message_add(d, EKEKO_MSG_CONTEXT_GET_REPLY, 0);
	/* context free */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Context_Free",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Context_Free));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "id", c,
			offsetof(Ekeko_Msg_Context_Free, id));
	EKEKO_MSG_CONTEXT_FREE = eix_message_add(d, NULL, 0);

	/* the image load reply */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Image_Load_Reply",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Image_Load_Reply));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "id", c,
			offsetof(Ekeko_Msg_Image_Load_Reply, id));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "width", c,
			offsetof(Ekeko_Msg_Image_Load_Reply, w));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "height", c,
			offsetof(Ekeko_Msg_Image_Load_Reply, h));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "offset", c,
			offsetof(Ekeko_Msg_Image_Load_Reply, offset));
	EKEKO_MSG_IMAGE_LOAD_REPLY = eix_message_add(d, NULL, 0);
	/* the image load */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Image_Load",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Image_Load));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "context_id", c,
			offsetof(Ekeko_Msg_Image_Load, context_id));
	c = ender_container_new(ENDER_STRING);
	p = ender_descriptor_struct_property_add(d, "file", c,
			offsetof(Ekeko_Msg_Image_Load, file));
	EKEKO_MSG_IMAGE_LOAD = eix_message_add(d, EKEKO_MSG_IMAGE_LOAD_REPLY, -1);
	/* image free */
	d = ender_namespace_descriptor_add(
			ns,
			"Ekeko_Msg_Image_Free",
			NULL,
			NULL,
			NULL,
			ENDER_TYPE_STRUCT, sizeof(Ekeko_Msg_Image_Free));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "context_id", c,
			offsetof(Ekeko_Msg_Image_Free, context_id));
	c = ender_container_new(ENDER_UINT32);
	p = ender_descriptor_struct_property_add(d, "id", c,
			offsetof(Ekeko_Msg_Image_Free, id));
	EKEKO_MSG_IMAGE_FREE = eix_message_add(d, NULL, 0);
}

void ekeko_common_message_shutdown(void)
{
	/* unregister the messages */
}
